package com.uzhie.jt808.msg.entity;

import com.uzhie.jt808.JT808MsgBody;

/**
 *
 * 多媒体上传命令
 * Created by lilongfei on 2018/8/11.
 */
public class JT_0800 implements JT808MsgBody {

    //多媒体id
    String ID;
    //多媒体类型  0 图片 1音频 2视频
    int type;
    //编码格式 0 jpg 1 tif 2 mp3 3 wav 4 wmv
    int encode;
    //事件编码  0 平台下发指令 1 定时动作 2 抢劫报警触发 3碰撞侧翻报警触发
    int event;
    //通道号
    int channel;


    public final static byte getOrderLength(){
        return 0x08;
    }

    public String getID() {
        return ID;
    }

    public void setID(String ID) {
        this.ID = ID;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public int getEncode() {
        return encode;
    }

    public String getStringEncode(){
        switch (encode){
            case 0:
                return "JPG";
            case 1:
                return "TIF";
            case 2:
                return "MP3";
            case 3:
                return "WAV";
            case 4:
                return "WMV";
            default:
                return "jpg";
        }
    }

    public void setEncode(int encode) {
        this.encode = encode;
    }

    public int getEvent() {
        return event;
    }

    public void setEvent(int event) {
        this.event = event;
    }

    public int getChannel() {
        return channel;
    }

    public void setChannel(int channel) {
        this.channel = channel;
    }

    public JT_0800(byte[] bytes){
        ReadFromBytes(bytes);
    }

    @Override
    public byte[] WriteToBytes() {
        MyBuffer buffer = new MyBuffer();
        buffer.put(getID());
        buffer.put(BitConverter.GetBytes(getType())[3]);
        buffer.put(BitConverter.GetBytes(getEncode())[3]);
        buffer.put(BitConverter.GetBytes(getEvent())[3]);
        buffer.put(BitConverter.GetBytes(getChannel())[3]);

        return buffer.array();
    }

    @Override
    public void ReadFromBytes(byte[] body) {
        MyBuffer buffer = new MyBuffer(body);
        setID(buffer.getString(4));
        setType(buffer.get());
        setEncode(buffer.get());
        setEvent(buffer.get());
        setChannel(buffer.get());
    }
}
